define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Myworldindex, GoPage, Auth, $rootScope,GoDialog) {
		//页面激活
		$scope.$on('$ionicView.afterEnter', function() {
			$scope.init_auth();
			//获取用户信息(人才市场)
			Myworldindex.getUserInfo(function(data){
				$scope.userInfo_recruitment = data;
			})
		}, false);
		
		$scope.init_auth = function() {
			//用户类型
			$scope.user_type = Auth.check_user_type();
			//判断权限
			$scope.user_info = Auth.get_loginInfo(); //$scope.user_info.is_warehouse是字符串类型的
//			console.log($scope.user_info)
			//菜单
			Myworldindex.get_menus(function(data) {
				$scope.AllMenus = new Array();
				for(var i = 0; i < data.menus.length; i++) {
					var obj = data.menus[i];
					obj.isshow = false;
					for(var j = 0; j < obj.type.length; j++) {
						if($scope.user_type == obj.type[j]) {
							obj.isshow = true;
							break; //一找到就退出
						}
					}
					$scope.AllMenus.push(obj);
				}
			});
		};


		//页面跳转
		$scope.onshow_myworld = function(value) {
			if(value != "recruitment"){
				GoPage.go_states(value);
			}else{//如果是人才市场，则跳转到第三方链接
				if(!$scope.userInfo_recruitment){
					GoDialog.confirm("请求失败","请先登录",function(){
						GoPage.go_states("t-login");
					})
				}else if($scope.userInfo_recruitment.verify_email!="Y"){//大写
					GoDialog.confirm("请求失败","请先绑定邮箱",function(){
						GoPage.go_states("linkemail");
					})
				}else{
					$scope.outUrl = HTTP_URL_RECRUITMENT+"?session="+$scope.userInfo_recruitment.session;
					GoPage.go_link($scope.outUrl);
				}
			}
		};
		
		//跳转到t-set
		$scope.onshow_t_set = function() {
			GoPage.go_states("t-set");
		};
		
		//查看头像大图
		$scope.showBigImg = function() {
			GoDialog.showBigImg($scope.user_info.store_qr);
		}
		

	}

	controller.$inject = ['$scope', 'Myworldindex', 'GoPage', 'Auth', '$rootScope','GoDialog'];

	return app.registerController("myworldindexctrl", controller);
});